/**
 * 
 * @param {String}   年-月-日 时:分:秒
 * @returns String
 */



function dateFormat(format) {
    //获取当前时间 s
    var nowTime = new Date()
    var nowTimes = nowTime.getTime()

    //获取传递实参时间 s
    var oldTime = new Date(format)
    var oldTimes = oldTime.getTime()

    //获取差值
    var diff = (nowTimes - oldTimes) / 1000
    if (diff < 10) return '刚刚'
    if (diff < 60) return diff + '秒前'
    if (diff < 60 * 60) return Math.floor(diff / 60) + '分钟前'
    if (diff < 60 * 60 * 60) return Math.floor(diff / 60 / 60) + '小时前'
    if (diff < 60 * 60 * 60 * 24) return Math.floor(diff / 60 / 60 / 24) + '天前'
    if (diff < 60 * 60 * 60 * 24 * 30) return Math.floor(diff / 60 / 60 / 24 / 30) + '月前'
    if (diff < 60 * 60 * 60 * 24 * 30 * 12) return Math.floor(diff / 60 / 60 / 24 / 30 / 12) + '年前'



}


/**
 * 字符串补零（注：传递过来的长度补足两位）
 * @param {String|Number} date 比如：日期数据4
 * @returns 过滤后的数据
 */


function zeroize(data) {
    return String(data).length == 1 ? '0' + data : data
}




/**
 * 
 * @param {String} str 
 * @returns String
 */

function format(str) {


    var d = new Date()


    str = str.replaceAll('y', d.getFullYear())
    str = str.replaceAll('m', zeroize(d.getMonth() + 1))
    str = str.replaceAll('r', zeroize(d.getDate()))
    str = str.replaceAll('h', zeroize(d.getHours()))
    str = str.replaceAll('i', zeroize(d.getMinutes()))
    str = str.replaceAll('s', zeroize(d.getSeconds()))
    return str
}

/**
 * 随机颜色
 * @returns String
 */

function randomColor() {
    var colorArr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 'A', 'B', 'C', 'D', 'E', 'F']
    var min = 0
    var max = colorArr.length - 1

    var first = colorArr[Math.floor(Math.random() * (max - min + 1) + min)]
    var two = colorArr[Math.floor(Math.random() * (max - min + 1) + min)]
    var three = colorArr[Math.floor(Math.random() * (max - min + 1) + min)]
    var four = colorArr[Math.floor(Math.random() * (max - min + 1) + min)]
    var fiver = colorArr[Math.floor(Math.random() * (max - min + 1) + min)]
    var six = colorArr[Math.floor(Math.random() * (max - min + 1) + min)]
    return '#' + first + two + three + four + fiver + six
}


/**
 * 判断浏览器内核
 *  String
 */

function myBrowser() {
    // 封装获取浏览器函数
    var ua = navigator.userAgent
    if (ua.indexOf('Firebox') > -1) { return '火狐浏览器' }
    if (ua.indexOf('Chrome') > -1) { return '谷歌浏览器' }
    if (ua.indexOf('Opera') > -1) { return 'opera浏览器' }
    if (ua.indexOf('Trident') > -1) { return 'IE浏览器' }
}

/**
   * 判断是否是微信
   */
function weChat() {
    var ua = navigator.userAgent
    if (ua.indexOf('micromessenger') > -1) {
        return true;
    }
    return false;
}

/**
   * 判断是否是否移动端
   */
function os() {
    var ua = navigator.userAgent
    if (ua.indexOf('Android|iPhone|webOS|iPod|BlackBerry') > 1) {
        return '移动端'
    } else {
        return 'pc端'
    }
}

/**
 * 返回标签样式
 * @param {tagObj,cssAttr}
 * @returns String
 */


function getStyle(tagObj, cssAttr) {
    if (window.getComputedStyle) {
        return getComputedStyle(tagObj)[cssAttr]
    } else {
        return tagObj.currentStyle[cssAttr]
    }
}



/**
 * 
 * @param {String} key 参数名
 * @returns String  参数的值
 */
function getParams(key) 
{
    // 获取url中？后面的数据
    // substr()
    // let query = decodeURI(window.location.search.substr(1))
    let query = decodeURI(window.location.href.split('?')[1])
    let arr = query.split('&')
    for (let i = 0; i < arr.length; i++) {
        let tempArr = arr[i].split('=')
        if (tempArr[0] === key) return tempArr[1]
    }
    return false
}
console.log(getParams('key'))
